#ifndef DXMANAGER
#define DXMANAGER

#include <windows.h>
#include <d3d10.h>
#include <d3dx10.h>

#include <vector>

#include "vertexTypes.h"
#include "BasicObjects.h"
#include "Camera.h"
#include "lights.h"
#include <atlbase.h> 
#include <atlconv.h>
#include "Drawable.h"
#include "hrTimer.h"

class dxManager
{
	/*******************************************************************
	* Members
	********************************************************************/	
private:

	//window handle shortcut
	HWND*						hWnd;
	
	//device vars
	ID3D10Device*				pD3DDevice;
	IDXGISwapChain*				pSwapChain;
	ID3D10RenderTargetView*		pRenderTargetView;
	ID3D10Texture2D*			pDepthStencil;
	ID3D10DepthStencilView*		pDepthStencilView;	
	D3D10_VIEWPORT				viewPort;
	ID3D10RasterizerState*		pRS;
	//input layout and mesh
	ID3D10InputLayout*			pVertexLayout;
	//ID3DX10Mesh*				pMesh;
	BasicObjects				basicobjects;
	//effects and techniques
	ID3D10Effect*				pBasicEffect;
	ID3D10EffectTechnique*		pBasicTechnique;
	//Depth Testing
	ID3D10DepthStencilState* m_depthStencilState;
	ID3D10DepthStencilView* m_depthStencilView;
	//effect variable pointers
	ID3D10EffectMatrixVariable* pViewMatrixEffectVariable;
	ID3D10EffectMatrixVariable* pProjectionMatrixEffectVariable;
	ID3D10EffectMatrixVariable* pWorldMatrixEffectVariable;
	
	//projection and view matrices
	D3DXMATRIX					worldMatrix;
	Camera camera;
	//technique
	D3D10_TECHNIQUE_DESC		techDesc;
	//texture storage
	std::vector<ID3D10ShaderResourceView*> textureSRV;
	ID3D10EffectShaderResourceVariable* pTextureSR;
	int textureIndex;
	//Textfont
	ID3DX10Font *d3dxFont;
	LPCWSTR infoText;
	RECT fontPosition;
	//Lights
	D3DXVECTOR4					ambientLight;
	DirectionalLight			directionalLight;
	Material					material;
	//RenderingTechniques
	LPCWSTR renderingTechniques[9];
	UINT renderingTechniquesIndex;
	//Drawable *drawObjects;
	//Timer
	timer rotTimer;
	/*******************************************************************
	* Methods
	********************************************************************/	
public:

	//constructor and destructor
	dxManager();
	~dxManager();

	//initialize directx device
	bool initialize(HWND*);	

	//scene function
	void renderScene();	
	Camera *getCamera();
	//Texturing
	LPCWSTR switchRenderingTech();
	void swapTexture();
	LPCWSTR getInfotext();
	void setInfoText(LPCWSTR text);
private:

	//initialization methods
	bool createSwapChainAndDevice( UINT width, UINT height );
	bool loadShadersAndCreateInputLayouts();
	void createViewports( UINT width, UINT height );
	void initRasterizerState();
	bool createRenderTargetsAndDepthBuffer( UINT width, UINT height );
	bool initializeObjects();
	//void initializeTestobjects();
	//texture loader	
	bool loadTextures();
	void drawBasicObjects();
	//fatal error handler
	bool fatalError(const LPCWSTR msg); 
};

#endif;